package com.xuecheng.framework.util;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

public class XcOauth2Util {

    public UserJwt getUserJwtFromHeader(HttpServletRequest request) {
        Map<String, String> jwtClaims = Oauth2Util.getJwtClaimsFromHeader(request);
        if (jwtClaims == null || StringUtils.isEmpty(jwtClaims.get("id"))) {
            return null;
        }
        UserJwt userJwt = new UserJwt();
        userJwt.setId(jwtClaims.get("id"));
        userJwt.setName(jwtClaims.get("name"));
        userJwt.setUserPicture(jwtClaims.get("userPicture"));
        userJwt.setUserType(jwtClaims.get("userType"));
        userJwt.setCompanyId(jwtClaims.get("companyId"));

        return userJwt;
    }

    @Data
    public class UserJwt {
        private String id;
        private String name;
        private String userPicture;
        private String userType;
        private String companyId;
    }

}
